frappe.query_reports["MES Quality Inspection Data Report"] = {
    "filters": [
        {
            "fieldname": "from_date",
            "label": __("开始日期"),
            "fieldtype": "Date",
            "default": frappe.datetime.add_days(frappe.datetime.get_today(), -7),
            "reqd": 0
        },
        {
            "fieldname": "to_date",
            "label": __("结束日期"),
            "fieldtype": "Date",
            "default": frappe.datetime.get_today(),
            "reqd": 0
        },
        {
            "fieldname": "product_code",
            "label": __("物料编码"),
            "fieldtype": "Link",
            "options": "Item",
            "reqd": 0
        },
        {
            "fieldname": "work_order",
            "label": __("工单名称"),
            "fieldtype": "Link",
            "options": "Work Order",
            "reqd": 0
        },
        {
            "fieldname": "inspection_result",
            "label": __("检测结果"),
            "fieldtype": "Select",
            "options": "\n合格\n不合格\n待定",
            "reqd": 0
        },
        {
            "fieldname": "process",
            "label": __("工序"),
            "fieldtype": "Data",
            "reqd": 0
        }
    ],
    
    "onload": function(report) {
        // 添加刷新按钮
        report.page.add_inner_button(__("刷新数据"), function() {
            report.refresh();
        });
    },
    
    "formatter": function(value, row, column, data, default_formatter) {
        value = default_formatter(value, row, column, data);
        
        if (column.fieldname == "inspection_result") {
            if (value == "合格") {
                value = `<span style="color: green; font-weight: bold;">${value}</span>`;
            } else if (value == "不合格") {
                value = `<span style="color: red; font-weight: bold;">${value}</span>`;
            } else if (value == "待定") {
                value = `<span style="color: orange; font-weight: bold;">${value}</span>`;
            }
        }
        
        return value;
    }
};
